#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int image[1000][2];
	int size = 0;
	int width;
	cin>>width;

	while (width != 0)
	{

		int pixel, runLength;
		cin>>pixel>>runLength;
		while (pixel != 0 && runLength != 0) {
			image[size][0] = pixel;
			image[size++][1] = runLength;
			cin>>pixel>>runLength;
		}
		int i = 0;
		for (i = 0; i < size; i++) {
			
		}
		cin>>width;
	}
	return 0;
}